package com.dareway.thread;



public class Thread_synchronized {
    private static int v = 1;

    private static synchronized void add() {
        v++;
    }

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
//            synchronized (Main.class) {
//                for (int i = 0; i < 1000; i ++ ) v ++;
//                System.out.println("线程1完成");
//            }
            for (int i = 0; i < 1000; i++) add();
            System.out.println("线程1完成");
        });
        Thread t2 = new Thread(() -> {
//            synchronized (Main.class) {
//                for (int i = 0; i < 1000; i ++ ) v ++;
//                System.out.println("线程2完成");
//            }
            for (int i = 0; i < 1000; i++) add();
            System.out.println("线程2完成");
        });
        t1.start();
        t2.start();
        Thread.sleep(1000);
        System.out.println(v);
    }
}
